//设置全局变量
let app = require("./demo_reposi/setLocals.js");
// console.log(app.locals.pg)

//用bodyparser解析
let bodyParser = require("body-parser");
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
//获取express对象
let express = require("express");

//设置静态文件访问路径
app.use(express.static("public"));

//连接数据库
let connectPgSql = require("./demo_reposi/pg.js");
let pg = new connectPgSql();
pg.startConnet();

app.get("/sql/:sql", function(req, res) {
  res.send(JSON.stringify(req.params));
});
app.post("/post", async function(req, res) {
  let data = await pg.getSql(req.body.content);
  res.send(data);
});
//启动服务器并且设置端口为1123
app.listen(1123);
